package com.book.web.controller.app;

import cn.hutool.core.lang.Validator;
import com.book.common.annotation.RepeatSubmit;
import com.book.common.core.controller.BaseController;
import com.book.common.core.domain.AjaxResult;
import com.book.common.utils.StringUtils;
import com.book.framework.web.service.AppRegisterService;
import com.book.system.domain.param.AppUserRegisterParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Bigboss
 * @create 2024-10-19 16:43
 */
@Api(tags = "app用户注册")
@RestController
public class AppRegisterController extends BaseController {

    private final AppRegisterService appRegisterService;

    public AppRegisterController(AppRegisterService appRegisterService) {
        this.appRegisterService = appRegisterService;
    }

    /**
     * app用户注册
     * @param user
     * @return
     */
    @ApiOperation(value = "app用户注册")
    @RepeatSubmit
    @PostMapping("/appRegister")
    public AjaxResult register(@RequestBody @Validated AppUserRegisterParam user)
    {
        //前置校验手机号是否合法
        if(!Validator.isMobile(user.getPhone())){
            return error("手机号信息不合法");
        }
        String msg = appRegisterService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
